﻿using MediatR;
using Newtonsoft.Json;
using PublicClass.HttpClient;
using S.Produce.Domains.CountDTO;
using S.Produce.Read.Api.Application.Commands.SheepCountCommands;

namespace S.Produce.Read.Api.Application.CommandHandlers.SheepCountCommandHandlers
{
    /// <summary>
    /// 近30日羊场存栏数量
    /// </summary>
    public class HerdstrendCountCommandHandler : IRequestHandler<HerdstrendCountCommand, HerdstrendCount>
    {
        private readonly ServiceHttpClient serviceHttpClient;

        /// <summary>
        /// 构造方式注入
        /// </summary>
        /// <param name="serviceHttpClient"></param>
        public HerdstrendCountCommandHandler(ServiceHttpClient serviceHttpClient)
        {
            this.serviceHttpClient = serviceHttpClient;
        }

        public async Task<HerdstrendCount> Handle(HerdstrendCountCommand request, CancellationToken cancellationToken)
        {
            var countClient = await serviceHttpClient.Get("http://10.31.56.15:8090/api/SheepFile/SheepFileConditionarown");
            var info = JsonConvert.DeserializeObject<List<SheepDetail>>(countClient);

            var dateName = new List<string>();
            for (int i = 0; i < 30; i++)
            {
                var count = 30;
                dateName.Add(DateTime.Now.Month + "/" + DateTime.Now.AddDays(-count).Day);
                count--;
            }
            return new HerdstrendCount();
        }
    }
}
